//
//  Tag.swift
//  hello
//
//  Created by 赵康 on 2024/11/11.
//

import Vapor
import Fluent

final class Tag: Model, Content, @unchecked Sendable {
	static var schema: String { SchemaEnum.tags.rawValue }
	
	@ID(key: .id)
	var id: UUID?
	
	@Field(key: FieldKeys.name)
	var name: String
	
	@Siblings(through: AlbumTag.self, from: \.$tag, to: \.$album)
	var albums: [Album]
	
	@OptionalField(key: FieldKeys.isDeleted)
	var isDeleted: Bool?
	
	@Timestamp(key: FieldKeys.createdAt, on: .create)
	var createdAt: Date?
	
	@Timestamp(key: FieldKeys.updatedAt, on: .update)
	var updatedAt: Date?
	
	init() { }
	
	init(id: UUID? = nil, name: String, isDeleted: Bool?, createdAt: Date?, updatedAt: Date?) {
		self.id = id
		self.name = name
		self.isDeleted = isDeleted
		self.createdAt = createdAt
		self.updatedAt = updatedAt
	}
}

struct TagResponse: Content {
	let id: UUID?
	let name: String
	
	init(id: UUID?, name: String) {
		self.id = id
		self.name = name
	}
}

extension Tag {
		struct Create: Content {
				var name: String
		}
}

// Tag 文学，历史，自然，教育，商业，生活，社会，科技，艺术，娱乐
